﻿<UserControl x:Class="EpiDashboard.Controls.DataFilterControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
             xmlns:Controls="clr-namespace:EpiDashboard.Controls"
             mc:Ignorable="d" 
             xmlns:EpiDashboard="clr-namespace:EpiDashboard"
             >


    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Rectangle Fill="White" Style="{DynamicResource shadowRectangleWhite}"></Rectangle>
        <Border Width="Auto" Name="borderAll" CornerRadius="0" Style="{DynamicResource mainGadgetBorder}" >
            <Grid x:Name="ConfigGrid" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5,5,5,5" >
                <!--<Rectangle Fill="#22000000" RadiusX="10" RadiusY="10" Margin="0,4,0,0" />
                <Rectangle Fill="#775C90B2" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" />
                <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="5,5,5,10" />-->
                <Grid Name="grdAll" Margin="7" HorizontalAlignment="Center" VerticalAlignment="Top" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="0"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition x:Name="rowSpacer2" Height="0"/>
                        <RowDefinition x:Name="rowAdvanced" Height="Auto"/>
                        <RowDefinition x:Name="rowSpacer3" Height="0"/>
                    </Grid.RowDefinitions>

                    <TextBlock x:Name="txtTitle" HorizontalAlignment="Left" VerticalAlignment="Top" Width="150" TextWrapping="Wrap" TextAlignment="Center" Text="Data Filters" FontWeight="Bold" >
                        <TextBlock.RenderTransform>
                            <RotateTransform Angle="270" CenterX="80" CenterY="81" />
                        </TextBlock.RenderTransform>
                    </TextBlock>

                    <Grid Name="grdSelectionProperties" Grid.Row="0" Width="Auto" HorizontalAlignment="Center" Margin="27,2,2,2" Visibility="Visible">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="23"/>
                            <RowDefinition Height="7"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="12"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="90"/>
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="40.899"/>
                            <ColumnDefinition Width="29.101"/>
                            <ColumnDefinition Width="26.017"/>
                            <ColumnDefinition Width="13.903"/>
                            <ColumnDefinition Width="98.097"/>
                            <ColumnDefinition Width="17.6"/>
                            <ColumnDefinition Width="94.4"/>
                            <ColumnDefinition Width="90"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="90"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock x:Name="lblConditions" HorizontalAlignment="Left" TextAlignment="Left" Text="Data filters:" Margin="0,5,0,0" Grid.Row="5" Grid.Column="0" Width="413" Grid.ColumnSpan="8" />
                        <ListBox x:Name="lbxConditions" HorizontalAlignment="Left" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="10" Width="514" Visibility="Collapsed"/>

                        <DataGrid x:Name="dgFilters" 
                                      HorizontalAlignment="Stretch" 
                                      HorizontalScrollBarVisibility="Hidden" 
                                      Grid.Row="6" 
                                      Grid.Column="0" 
                                      Grid.ColumnSpan="10"                                       
                                      CanUserReorderColumns="False" 
                                      CanUserResizeColumns="True" 
                                      CanUserResizeRows="False" 
                                      CanUserSortColumns="False"                                       
                                      CanUserAddRows="False" 
                                      CanUserDeleteRows="False"
                                      RowHeight="18" IsReadOnly="True" SelectionMode="Single" SelectionChanged="dgFilters_SelectionChanged" Margin="2,0,9,0" >

                            <DataGrid.ColumnHeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="FontSize" Value="14" />
                                    <Setter Property="FontWeight" Value="SemiBold" />
                                    <Setter Property="FontFamily" Value="Calibri, Global User Interface" />
                                    <Setter Property="Background" Value="#4F81BD" />
                                    <Setter Property="Foreground" Value="White" />
                                    <Setter Property="BorderThickness" Value="0,0,1,1" />
                                    <Setter Property="BorderBrush" Value="#D5D5D5" />
                                    <Setter Property="Padding" Value="4" />
                                </Style>
                            </DataGrid.ColumnHeaderStyle>

                            <DataGrid.CellStyle>
                                <Style TargetType="DataGridCell">
                                    <Setter Property="FontSize" Value="12" />
                                    <Setter Property="FontFamily" Value="Calibri, Global User Interface" />
                                    <Setter Property="FontWeight" Value="Normal"/>

                                </Style>
                            </DataGrid.CellStyle>
                        </DataGrid>



                        <TextBlock x:Name="lblFieldName" HorizontalAlignment="Left" TextAlignment="Left" Text="Field Name:" Margin="2,-7,0,12" Grid.Row="0" Width="196" Grid.ColumnSpan="5"  />
                        <ComboBox x:Name="cbxFieldName" HorizontalAlignment="Left" SelectedIndex="0" SelectionChanged="cbxFieldName_SelectionChanged" Margin="0,9,0,11" Grid.RowSpan="2" Grid.ColumnSpan="5" Width="204" />

                        <TextBlock x:Name="lblOperator" HorizontalAlignment="Left" TextAlignment="Left" Text="Operator:" Margin="2,-8,0,13" Grid.Row="0" Grid.Column="5" Grid.ColumnSpan="2" Width="100"  />
                        <ComboBox x:Name="cbxOperator"  HorizontalAlignment="Left" SelectedIndex="0" Grid.Column="5" MaxWidth="110" MinWidth="110" SelectionChanged="cbxOperator_SelectionChanged" Margin="1,9,0,11" Grid.RowSpan="2" Width="110" Grid.ColumnSpan="2" />

                        <TextBlock x:Name="txtValue" HorizontalAlignment="Left" TextAlignment="Left" Text="Value:" Margin="4,-7,0,12" Grid.Row="0" Grid.Column="7" Width="190" Grid.ColumnSpan="3"  />
                        <ComboBox IsTextSearchEnabled="True" IsEditable="True" x:Name="cbxValue" HorizontalAlignment="Left" Grid.Column="7" Visibility="Hidden"  MinWidth="110" Margin="3,9,0,11" Grid.ColumnSpan="3" Width="200" RenderTransformOrigin="0.542,1.628" Grid.RowSpan="2"/>

                        <DatePicker x:Name="dateValue" HorizontalAlignment="Left" Grid.Column="7" MinWidth="90" Visibility="Hidden" Margin="4,9,0,11" Grid.RowSpan="2" Grid.ColumnSpan="3" Width="201" >
                            <DatePicker.Resources>
                                <Style TargetType="Button">
                                    <Setter Property="MaxHeight" Value="30" />
                                </Style>
                            </DatePicker.Resources>

                        </DatePicker>
                        <TextBox x:Name="tbxNumericValue" HorizontalAlignment="Left" Grid.Column="7" Width="200" MinWidth="90" Visibility="Hidden" PreviewTextInput="tbxNumericValue_PreviewTextInput" Margin="4,8,0,12" Grid.ColumnSpan="3" Grid.RowSpan="2" />
                        <TextBox x:Name="tbxValue" HorizontalAlignment="Left" Grid.Column="7" Width="200" MinWidth="90" Visibility="Hidden" Margin="4,8,0,12" Grid.ColumnSpan="3" Grid.RowSpan="2" />

                        <TextBox x:Name="tbxLowValue" HorizontalAlignment="Left" Grid.Column="7" Width="200"  Visibility="Visible" PreviewTextInput="tbxNumericValue_PreviewTextInput" Grid.ColumnSpan="3" RenderTransformOrigin="0.509,-0.904" Margin="4,9,0,11" Grid.RowSpan="2" />
                        <TextBox x:Name="tbxHighValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="7" Width="200"  Visibility="Visible" PreviewTextInput="tbxNumericValue_PreviewTextInput" Grid.ColumnSpan="3" Margin="4,21,0,6" Grid.RowSpan="3" />

                        <DatePicker x:Name="dateLowValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="7" Width="203" Visibility="Hidden" Margin="4,21,-1,6" Grid.ColumnSpan="3" Grid.RowSpan="3" RenderTransformOrigin="0.502,0.714">
                            <DatePicker.Resources>
                                <Style TargetType="Button">
                                    <Setter Property="MaxHeight" Value="30" />
                                </Style>
                            </DatePicker.Resources>
                        </DatePicker>
                        <DatePicker x:Name="dateHighValue" HorizontalAlignment="Left" Grid.Column="7" MinWidth="90" Visibility="Hidden" Grid.ColumnSpan="3" Margin="4,9,0,11" Grid.RowSpan="2" Width="202">
                            <DatePicker.Resources>
                                <Style TargetType="Button">
                                    <Setter Property="MaxHeight" Value="30" />
                                </Style>
                            </DatePicker.Resources>
                        </DatePicker>

                        <TextBlock x:Name="txtAnd" Visibility="Visible" Text="and" TextAlignment="Right" HorizontalAlignment="Left" Margin="0,4,0,9" Grid.Column="6" Grid.Row="2" RenderTransformOrigin="-6.513,4.164" Grid.RowSpan="2" VerticalAlignment="Center" Width="84" Height="14"/>

                        <Button x:Name="btnNewCondition" Width="100" Grid.ColumnSpan="4" Content="Add Filter" Grid.Row="3" HorizontalAlignment="Left" Click="btnNewCondition_Click" Margin="0,10,0,2" Grid.RowSpan="2">
                            <Button.ContextMenu>
                                <ContextMenu>
                                    <MenuItem x:Name="mnuAddWithAnd" Header="Add Condition with AND" Click="mnuAddWithAnd_Click" />
                                    <MenuItem x:Name="mnuAddWithOr" Header="Add Condition with OR" Click="mnuAddWithOr_Click" />
                                </ContextMenu>
                            </Button.ContextMenu>
                        </Button>

                        <StackPanel x:Name="panelAdvanced" Visibility="Collapsed" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="8" Margin="0,0,90,0" >
                            <TextBlock x:Name="lblRecordProcessScope" HorizontalAlignment="Left" TextAlignment="Center" Text="Record processing scope:" Grid.ColumnSpan="2"/>
                            <ComboBox x:Name="cbxRecordProcessScope" HorizontalAlignment="Left" MaxWidth="140" Width="140" IsEditable="False" Grid.ColumnSpan="3" SelectionChanged="cbxRecordProcessScope_SelectionChanged" />
                        </StackPanel>

                        <TextBlock x:Name="tbkTheValueOf" TextWrapping="Wrap" Visibility="Hidden" HorizontalAlignment="Left" TextAlignment="Center" Text="The value of  " Grid.Column="0" Margin="0,14,0,3" Grid.RowSpan="2" VerticalAlignment="Center" Height="26" Width="44" Grid.ColumnSpan="2" />
                    </Grid>

                    <Grid x:Name="grdGuidedModeButtons" VerticalAlignment="Top" Grid.Row="2" Margin="27, 5, 5, 5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="135"/>
                            <ColumnDefinition Width="135"/>
                            <ColumnDefinition Width="135"/>
                        </Grid.ColumnDefinitions>

                        <Button x:Name="btnRemoveCondition" Width="120" Grid.ColumnSpan="2" Content="Remove Selected" Grid.Row="0" HorizontalAlignment="Left" Click="btnRemoveCondition_Click" />
                        <Button x:Name="btnClearConditions" Width="120" Grid.ColumnSpan="2" Content="Clear All" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Click="btnClearConditions_Click" />
                        <Button x:Name="btnAdvancedMode" Width="120" Grid.ColumnSpan="2" Content="Advanced Mode" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" Click="btnAdvancedMode_Click" />
                    </Grid>

                    <StackPanel Grid.Row="4" x:Name="pnlAdvancedMode" VerticalAlignment="Top" Margin="27, 0, 0, 0">
                        <TextBlock x:Name="lblAdvancedFilterMode" Text="Advanced Filter Mode" FontWeight="Bold" Margin="0, 0, 0, 3" />
                        <TextBlock x:Name="tblockAdvancedInstruct" Text="Type the desired data filter string into the text box below. Several examples are provided:" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left"
                               Margin="0, 0, 0, 3" />

                        <TextBlock x:Name="lblAdvancedNumeric" Text="  1. Numeric data:   (AGE &gt;= 15) AND (AGE &lt;= 45)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                        <TextBlock x:Name="lblAdvancedText" Text="  2. Text data:   (LastName LIKE '%sen') OR (LastName = 'Smith')" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                        <TextBlock x:Name="lblAdvancedDate" Text="  3. Date data:   (DOB &gt;= #01/01/2000#) AND (DOB &lt;= #12/31/2000 23:59:59#)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                        <TextBlock x:Name="lblAdvancedBool" Text="  4. Boolean data:   (ILL = true)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />


                        <TextBox x:Name="txtAdvancedFilter" Margin="0, 5, 0, 0" Height="40" TextWrapping="Wrap" MaxWidth="516" TextChanged="txtAdvancedFilter_TextChanged" />
                        <TextBox x:Name="txtAdvancedFilterStatus" IsReadOnly="True" Margin="0, 5, 0, 0" TextWrapping="Wrap" />

                        <Grid x:Name="grdAdvancedModeButtons">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="140"/>
                                <ColumnDefinition Width="140"/>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="10" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="20" />
                            </Grid.RowDefinitions>
                            <Button x:Name="btnApplyAdvancedFilter" Grid.Row="1" Grid.Column="0" Width="120" Content="Apply Filter" HorizontalAlignment="Left" Click="btnApplyAdvancedFilter_Click" />
                            <Button x:Name="btnGuidedMode"          Grid.Row="1" Grid.Column="1" Width="120" Content="Guided Mode" Click="btnAdvancedMode_Click" HorizontalAlignment="Left" />
                        </Grid>


                    </StackPanel>


                </Grid>
            </Grid>
        </Border>
        <Image x:Name="imgClose" Visibility="Collapsed" Source="..\Images\x_over.png" Cursor="Hand" HorizontalAlignment="Right" Margin="7" VerticalAlignment="Top" Stretch="None" />
    </Grid>

</UserControl>
